<?php

namespace plugin\enterprise\app\controller;

use plugin\enterprise\app\Enterprise;
use plugin\owladmin\app\model\Plugin;
use support\Request;
use support\Response;

class IndexController extends \plugin\owladmin\app\controller\IndexController
{

    public function menus(): Response
    {
        return $this->response()->success(Enterprise::menu()->all());
    }


    public function settings(): \support\Response
    {
        $prefix = '';
        $localeOptions = Enterprise::config('enterprise.layout.locale_options') ?? [
            'en'    => 'English',
            'zh_CN' => '简体中文',
        ];
        return $this->response()->success([
            'nav'      => Enterprise::getNav(),
            'assets'   => Enterprise::getAssets(),
            'app_name' => Enterprise::config('enterprise.name'),
            'locale'   => settings()->get('enterprise_locale', config('plugin.enterprise.translation.locale')),
            'layout'   => Enterprise::config('enterprise.layout'),
            'logo'     => url(Enterprise::config('enterprise.logo')),

            'login_captcha'          => Enterprise::config('enterprise.auth.login_captcha'),
            'locale_options'         => map2options($localeOptions),
            'show_development_tools' => Enterprise::config('enterprise.show_development_tools'),
            'system_theme_setting'   => Enterprise::setting()->get($prefix . 'system_theme_setting'),
            'enabled_extensions'     => Plugin::query()->where('is_enabled', 1)->pluck('name')?->toArray(),
        ]);
    }


    public function saveSettings(Request $request): Response
    {
        $data = $request->all();
        Enterprise::setting()->setMany($data);
        return $this->response()->successMessage();
    }

}
